package org.leiyang.service.impls;

import org.leiyang.common.dtos.MsgDTO;
import org.leiyang.common.dtos.OffLineMsgsVO;
import org.leiyang.common.service.RemoteCall;
import org.leiyang.config.RSocketConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 非Feign方式的远程调用
 */
@Service
public class RemoteCallImpl extends RemoteCall{
    private final Logger logger = LoggerFactory.getLogger(getClass());

    private final RSocketConfig rSocketConfig;
    public RemoteCallImpl(RSocketConfig rSocketConfig) {
        this.rSocketConfig = rSocketConfig;
    }

    /**
     * 远程调用接口批量发送消息集
     */
    public Mono<Boolean> batchSendOffLineMsgs(List<MsgDTO> msgs, String channelId, String serverIpPort, Boolean onlineMsg) {
        logger.info("开始基于RSocket远程调用localsend接口.");
        OffLineMsgsVO offLineMsgsVO = OffLineMsgsVO.builder().msgs(msgs).channelId(channelId).onlineMsg(onlineMsg).build();
//        return gotCahcedWebClient(serverIpPort)
//                .post()
//                .uri("/local/batch/send")
//                .contentType(MediaType.APPLICATION_JSON)
//                .bodyValue(offLineMsgsVO)
//                .retrieve()
//                .bodyToMono(Boolean.class);
        return rSocketConfig.sendOffLineMsgsByRSStub(serverIpPort, offLineMsgsVO);
    }
}